﻿namespace WMS6.Web.Inbound
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.CommonMethodService2Ref;
    using WMS6.Web.InboundDetailServiceRef;
    using WMS6.Web.InboundServiceRef;
    using WMS6.Web.LoginServiceRef;
    using WMS6.Web.UserControls;

    public class Receiving : BasePage
    {
        protected Button btnAddDetail;
        protected Button btnBatchReceive;
        protected Button btnConfirmPA;
        protected Button btnDeleteDetail;
        protected Button btnDeletePA;
        protected Button btnGoBack;
        protected Button btnRefresh;
        protected Button btnReleasePrintPutaway;
        protected Button btnSave;
        protected CheckBox chbSAPAuthentication;
        protected CheckBox chkboxPalletAudit;
        protected DropDownList ddlReceiptType;
        protected DropDownList ddlStatus;
        protected HtmlForm F4021;
        protected GridView gvPutawayDetail;
        protected GridView gvReceiptDetail;
        protected GridView gvReceiptHistory;
        protected HtmlInputHidden hdnAction;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnCreatedBy;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnReceiptID;
        protected HtmlInputHidden hdnRtnValue;
        protected HtmlInputButton htmlbtnAction;
        protected HtmlInputButton htmlbtnReport;
        protected Label Label1;
        protected Label lblASN;
        protected Label lblExceptReceiptDate;
        protected Label lblExternalReceiptID;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblPackingSlipNum;
        protected Label lblPDTotal;
        protected Label lblPDTotalQty;
        protected Label lblPOID;
        protected Label lblReceiptDate;
        protected Label lblReceiptID;
        protected Label lblReceiptType;
        protected Label lblRHTotal;
        protected Label lblRHTotalReceived;
        protected Label lblRHTotalReceivedQty;
        protected Label lblRMA;
        protected Label lblStatus;
        protected Label lblTotal;
        protected Label lblTotalAllocated;
        protected Label lblTotalAllocatedQty;
        protected Label lblTotalCompleted;
        protected Label lblTotalCompletedQty;
        protected Label lblTotalCube;
        protected Label lblTotalExceptQty;
        protected Label lblTotalExpected;
        protected Label lblTotalExpectedQty;
        protected Label lblTotalGrossWeight;
        protected Label lblTotalReceiptQty;
        protected Label lblTotalReceived;
        protected Label lblTotalReceivedQty;
        protected Label lblVendorID;
        protected Label lblVendorRef;
        protected Label lblWaraHouseRef;
        protected LinkButton lnkbtnAutoputaway;
        protected LinkButton lnkbtnClose;
        protected LinkButton lnkbtnInvPalletInput;
        protected LinkButton lnkbtnPrintImportReceipt;
        protected LinkButton lnkbtnPrintPaymentBill;
        protected LinkButton lnkbtnPrintPutAway;
        protected LinkButton lnkbtnPrintQCReport;
        protected LinkButton lnkbtnPrintReceipt;
        protected LinkButton lnkbtnPrintReceiptList;
        protected LinkButton lnkbtnPrintReceivableBill;
        protected LinkButton lnkbtnReceiveall;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        private decimal PDtotalQty;
        protected Pager PutawayDetailPagerFooter;
        protected Pager ReceiptDetailPagerFooter;
        protected Pager ReceiptHistoryPagerFooter;
        private decimal RHTotalReceived;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnAutoputaway;
        protected HtmlTableCell tdlnkbtnClose;
        protected HtmlTableCell tdlnkbtnInvPalletInput;
        protected HtmlTableCell tdlnkbtnPrintImportReceipt;
        protected HtmlTableCell tdlnkbtnPrintPaymentBill;
        protected HtmlTableCell tdlnkbtnPrintPutAway;
        protected HtmlTableCell tdlnkbtnPrintQCReport;
        protected HtmlTableCell tdlnkbtnPrintReceipt;
        protected HtmlTableCell tdlnkbtnPrintReceiptList;
        protected HtmlTableCell tdlnkbtnPrintReceivableBill;
        protected HtmlTableCell tdlnkbtnReceiveall;
        private decimal TotalAllocated;
        private decimal TotalCompleted;
        private decimal totalExpectedQty;
        private decimal totalReceivedQty;
        protected TextBox txtExceptReceiptDate;
        protected TextBox txtExternalReceiptID;
        protected TextBox txtOwnerID;
        protected TextBox txtPackingSlipNum;
        protected TextBox txtPoID;
        protected TextBox txtReceiptDate;
        protected TextBox txtReceiptID;
        protected TextBox txtRMA;
        protected TextBox txtTotalCube;
        protected TextBox txtTotalExceptQty;
        protected TextBox txtTotalGrossWeight;
        protected TextBox txtTotalReceiptQty;
        protected TextBox txtVendorID;
        protected TextBox txtVendorRef;
        protected TextBox txtWaraHouseRef;
        protected UpdatePanel UpdatePanel1;
        protected UpdatePanel UpdatePanel2;
        protected UpdatePanel UpdatePanel3;

        private void AutoPutAway()
        {
            this.lblMsg.Visible = false;
            try
            {
                if (this.gvReceiptHistory.Rows.Count > 0)
                {
                    string result = string.Empty;
                    string receiptID = this.gvReceiptHistory.DataKeys[0]["RECEIPT_ID"].ToString();
                    List<string> receiptLineID = new List<string>();
                    string msg = string.Empty;
                    string tempNonLpn = string.Empty;
                    string tempNonPending = string.Empty;
                    string isNeedLPN = base.GetSysSettingValueByID("AutoPurawayNeedLPN");
                    for (int i = 0; i < this.gvReceiptHistory.Rows.Count; i++)
                    {
                        if (((CheckBox) this.gvReceiptHistory.Rows[i].FindControl("chbSelect")).Checked)
                        {
                            if (this.gvReceiptHistory.DataKeys[i]["STATUS"].ToString().ToUpper() != "COMPLETED")
                            {
                                if (isNeedLPN == "Y")
                                {
                                    if (!string.IsNullOrEmpty(this.gvReceiptHistory.DataKeys[i]["TO_LPN_ID"].ToString()))
                                    {
                                        receiptLineID.Add(this.gvReceiptHistory.DataKeys[i]["RECEIPT_LINE_ID"].ToString());
                                    }
                                    else
                                    {
                                        tempNonLpn = tempNonLpn + this.gvReceiptHistory.DataKeys[i]["TRANS_ID"].ToString() + ",";
                                    }
                                }
                                else
                                {
                                    receiptLineID.Add(this.gvReceiptHistory.DataKeys[i]["RECEIPT_LINE_ID"].ToString());
                                }
                            }
                            else
                            {
                                tempNonPending = tempNonPending + this.gvReceiptHistory.DataKeys[i]["TRANS_ID"].ToString() + ",";
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(tempNonLpn))
                    {
                        msg = msg + tempNonLpn.Substring(0, tempNonLpn.Length - 1) + base.GetGlobalMsgResource("F4200_013");
                    }
                    if (!string.IsNullOrEmpty(tempNonPending))
                    {
                        msg = msg + tempNonPending.Substring(0, tempNonPending.Length - 1) + base.GetGlobalMsgResource("F4200_014");
                    }
                    if (!string.IsNullOrEmpty(msg))
                    {
                        this.lblMsg.Text = msg;
                        this.lblMsg.Visible = true;
                    }
                    else
                    {
                        if ((receiptLineID != null) && (receiptLineID.Count > 0))
                        {
                            result = InboundDetailServiceClientProxy.GetInstance().AutoPutAway(receiptID, receiptLineID, base.UserInfo.UserID);
                        }
                        else
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F4200_012");
                            this.lblMsg.Visible = true;
                            return;
                        }
                        if (!string.IsNullOrEmpty(result))
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F4200_015");
                            this.lblMsg.Visible = true;
                        }
                        else
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F4200_016");
                            this.lblMsg.Visible = true;
                        }
                        this.SetReceiptInfo2Form();
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_017");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,4);$.unblockUI();</script>", false);
            }
        }

        private void BatchReceiving()
        {
            try
            {
                if (this.gvReceiptDetail.Rows.Count > 0)
                {
                    string receiptID = this.gvReceiptDetail.DataKeys[0]["RECEIPT_ID"].ToString();
                    List<string> receiptLineID = new List<string>();
                    for (int i = 0; i < this.gvReceiptDetail.Rows.Count; i++)
                    {
                        if (((CheckBox) this.gvReceiptDetail.Rows[i].FindControl("chbSelect")).Checked)
                        {
                            receiptLineID.Add(this.gvReceiptDetail.DataKeys[i]["RECEIPT_LINE_ID"].ToString());
                        }
                    }
                    if ((receiptLineID != null) && (receiptLineID.Count > 0))
                    {
                        if (!string.IsNullOrEmpty(InboundDetailServiceClientProxy.GetInstance().BatchReceiving(receiptID, receiptLineID)))
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F4200_009");
                            this.lblMsg.Visible = true;
                        }
                        else
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F4200_011");
                            this.lblMsg.Visible = true;
                        }
                        this.SetReceiptInfo2Form();
                        if (this.ddlStatus.SelectedValue == "ReceivedComplete")
                        {
                            List<string> mailList = new List<string> {
                                DateTime.Now.ToString(),
                                this.txtReceiptID.Text,
                                base.UserInfo.UserName
                            };
                            WMS6.Web.LoginServiceRef.UserMstInfo user = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.hdnCreatedBy.Value, "USER_MST") as WMS6.Web.LoginServiceRef.UserMstInfo;
                            if (user != null)
                            {
                                base.SandMail("Receiving", mailList, user.Email);
                            }
                        }
                    }
                    else
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F4200_012");
                        this.lblMsg.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,4);$.unblockUI();</script>", false);
            }
        }

        private void BindDataPutawayDetail(DataSet ds)
        {
            if (ds != null)
            {
                base.BindData2GridView(this.gvPutawayDetail, ds);
                this.gvPutawayDetail.Columns[1].Visible = true;
                if ((ds != null) && (ds.Tables.Count > 1))
                {
                    this.PutawayDetailPagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                    this.PutawayDetailPagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
                }
            }
            this.UpdatePanel3.Update();
        }

        private void BindDataReceiptDetail(DataSet ds)
        {
            if (ds != null)
            {
                base.BindData2GridView(this.gvReceiptDetail, ds);
                this.gvReceiptDetail.Columns[1].Visible = true;
                if ((ds != null) && (ds.Tables.Count > 1))
                {
                    this.ReceiptDetailPagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                    this.ReceiptDetailPagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
                }
            }
            this.UpdatePanel1.Update();
        }

        private void BindDataReceiptHistory(DataSet ds)
        {
            if (ds != null)
            {
                base.BindData2GridView(this.gvReceiptHistory, ds);
                this.gvReceiptHistory.Columns[1].Visible = true;
                if ((ds != null) && (ds.Tables.Count > 1))
                {
                    this.ReceiptHistoryPagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                    this.ReceiptHistoryPagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
                }
            }
            this.UpdatePanel2.Update();
        }

        protected void btnBatchReceive_Click(object sender, EventArgs e)
        {
            this.BatchReceiving();
        }

        protected void btnConfirmPA_Click(object sender, EventArgs e)
        {
            try
            {
                List<WMS6.Web.InboundDetailServiceRef.PutawayDetailInfo> putawayDetailInfos = new List<WMS6.Web.InboundDetailServiceRef.PutawayDetailInfo>();
                WMS6.Web.InboundDetailServiceRef.PutawayDetailInfo putawayDetail = null;
                for (int i = 0; i < this.gvPutawayDetail.Rows.Count; i++)
                {
                    if (((CheckBox) this.gvPutawayDetail.Rows[i].FindControl("chbSelect")).Checked && (this.gvPutawayDetail.DataKeys[i]["STATUS"].ToString().ToUpper() != "COMPLETED"))
                    {
                        putawayDetail = new WMS6.Web.InboundDetailServiceRef.PutawayDetailInfo {
                            TaskDetailID = this.gvPutawayDetail.DataKeys[i]["TASK_DETAIL_ID"].ToString(),
                            ReceiptID = this.gvPutawayDetail.DataKeys[i]["RECEIPT_ID"].ToString(),
                            ReceiptLineID = this.gvPutawayDetail.DataKeys[i]["RECEIPT_LINE_ID"].ToString()
                        };
                        if (((TextBox) this.gvPutawayDetail.Rows[i].FindControl("txtFinalLoc")) == null)
                        {
                            throw new Exception("[确认货位]文本框不存在,请将其设置为显示!");
                        }
                        putawayDetail.FinalLoc = ((TextBox) this.gvPutawayDetail.Rows[i].FindControl("txtFinalLoc")).Text.Trim();
                        putawayDetail.FromLpnID = this.gvPutawayDetail.DataKeys[i]["FROM_LPN_ID"].ToString();
                        putawayDetail.FromLoc = this.gvPutawayDetail.DataKeys[i]["FROM_LOC"].ToString();
                        putawayDetail.LotID = this.gvPutawayDetail.DataKeys[i]["LOT"].ToString();
                        putawayDetail.LpnID = this.gvPutawayDetail.DataKeys[i]["TO_LPN_ID"].ToString();
                        putawayDetail.Qty = decimal.Parse(this.gvPutawayDetail.DataKeys[i]["QTY"].ToString());
                        putawayDetail.OwnerID = this.gvPutawayDetail.DataKeys[i]["OWNER_ID"].ToString();
                        putawayDetail.SkuID = this.gvPutawayDetail.DataKeys[i]["SKU_ID"].ToString();
                        putawayDetail.Status = this.gvPutawayDetail.DataKeys[i]["STATUS"].ToString();
                        putawayDetail.SuggestLoc = this.gvPutawayDetail.DataKeys[i]["TO_LOC"].ToString();
                        putawayDetail.PackID = this.gvPutawayDetail.DataKeys[i]["PACK_ID"].ToString();
                        putawayDetail.UomID = this.gvPutawayDetail.DataKeys[i]["UOM_ID"].ToString();
                        putawayDetail.UpdatedBy = base.UserInfo.UserID;
                        putawayDetailInfos.Add(putawayDetail);
                    }
                }
                if (putawayDetailInfos.Count == 0)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_004");
                    this.lblMsg.Visible = true;
                }
                else if (int.Parse(InboundDetailServiceClientProxy.GetInstance().ConfirmPutAway(putawayDetailInfos)) > 0)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_005");
                    this.lblMsg.Visible = true;
                    this.SetReceiptInfo2Form();
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_006");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);$.unblockUI();</script>", false);
            }
        }

        protected void btnDeletePA_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> paTaskID = new List<string>();
                for (int i = 0; i < this.gvPutawayDetail.Rows.Count; i++)
                {
                    if (((CheckBox) this.gvPutawayDetail.Rows[i].FindControl("chbSelect")).Checked && (this.gvPutawayDetail.DataKeys[i]["STATUS"].ToString().ToUpper() != "COMPLETED"))
                    {
                        paTaskID.Add(this.gvPutawayDetail.DataKeys[i]["TASK_DETAIL_ID"].ToString());
                    }
                }
                if ((paTaskID != null) && (paTaskID.Count > 0))
                {
                    this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F4200_007"), TaskMgtServiceClientProxy.GetInstance().DeleteTaskDetail(paTaskID));
                    this.SetReceiptInfo2Form();
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_008");
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);$.unblockUI();</script>", false);
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("ReceivingQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("ReceivingList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            this.SetReceiptInfo2Form();
            if (!string.IsNullOrEmpty(this.hdnRtnValue.Value))
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one'," + this.hdnRtnValue.Value + ",4)</script>", false);
            }
        }

        protected void btnReleasePrintPutaway_Click(object sender, EventArgs e)
        {
            try
            {
                List<PrintControlInfo> printControlInfos = new List<PrintControlInfo>();
                for (int i = 0; i < this.gvPutawayDetail.Rows.Count; i++)
                {
                    if (((CheckBox) this.gvPutawayDetail.Rows[i].FindControl("chbSelect")).Checked && (this.gvPutawayDetail.DataKeys[i]["IS_PRINTED"].ToString().ToUpper() == "Y"))
                    {
                        PrintControlInfo printControlInfo = new PrintControlInfo {
                            PrintType = "PrintPutaway",
                            DocID = this.txtReceiptID.Text.Trim(),
                            DocLineID = this.gvPutawayDetail.DataKeys[i]["TASK_DETAIL_ID"].ToString()
                        };
                        printControlInfos.Add(printControlInfo);
                    }
                }
                if ((printControlInfos != null) && (printControlInfos.Count > 0))
                {
                    this.lblMsg.Text = string.Format("{0}任务打印已重置.", CommoneMethodService2ClientProxy.GetInstance().ReleasePrintControl(printControlInfos));
                    this.lblMsg.Visible = true;
                    this.SetReceiptInfo2Form();
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_012");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);$.unblockUI();</script>", false);
            }
        }

        private WMS6.Web.InboundServiceRef.PutawayDetailQueryEntity ConvertPutawayDetailQueryEntityByInBound(WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            WMS6.Web.InboundServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntityInbound = null;
            if (putawayDetailQueryEntity != null)
            {
                putawayDetailQueryEntityInbound = new WMS6.Web.InboundServiceRef.PutawayDetailQueryEntity {
                    IsGetAll = putawayDetailQueryEntity.IsGetAll,
                    CurrentPage = putawayDetailQueryEntity.CurrentPage,
                    PageSize = putawayDetailQueryEntity.PageSize,
                    SortField = putawayDetailQueryEntity.SortField,
                    SortDirection = putawayDetailQueryEntity.SortDirection,
                    ReceiptID = putawayDetailQueryEntity.ReceiptID
                };
            }
            return putawayDetailQueryEntityInbound;
        }

        private WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity ConvertPutawayDetailQueryEntityByInBoundDetail(WMS6.Web.InboundServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntityInboundDetail = new WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity();
            if (putawayDetailQueryEntity != null)
            {
                putawayDetailQueryEntityInboundDetail.IsGetAll = putawayDetailQueryEntity.IsGetAll;
                putawayDetailQueryEntityInboundDetail.CurrentPage = putawayDetailQueryEntity.CurrentPage;
                putawayDetailQueryEntityInboundDetail.PageSize = putawayDetailQueryEntity.PageSize;
                putawayDetailQueryEntityInboundDetail.SortField = putawayDetailQueryEntity.SortField;
                putawayDetailQueryEntityInboundDetail.SortDirection = putawayDetailQueryEntity.SortDirection;
                putawayDetailQueryEntityInboundDetail.ReceiptID = putawayDetailQueryEntity.ReceiptID;
            }
            return putawayDetailQueryEntityInboundDetail;
        }

        private WMS6.Web.InboundServiceRef.ReceiptDetailQueryEntity ConvertReceiptDetailQueryEntityByInBound(WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptdetailQueryEntity)
        {
            WMS6.Web.InboundServiceRef.ReceiptDetailQueryEntity receiptDetailQueryInboundDetail = null;
            if (receiptdetailQueryEntity != null)
            {
                receiptDetailQueryInboundDetail = new WMS6.Web.InboundServiceRef.ReceiptDetailQueryEntity {
                    IsGetAll = receiptdetailQueryEntity.IsGetAll,
                    CurrentPage = receiptdetailQueryEntity.CurrentPage,
                    PageSize = receiptdetailQueryEntity.PageSize,
                    SortField = receiptdetailQueryEntity.SortField,
                    SortDirection = receiptdetailQueryEntity.SortDirection,
                    IsPalletized = receiptdetailQueryEntity.IsPalletized,
                    ReceiptID = receiptdetailQueryEntity.ReceiptID
                };
            }
            return receiptDetailQueryInboundDetail;
        }

        private WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity ConvertReceiptDetailQueryEntityByInBoundDetail(WMS6.Web.InboundServiceRef.ReceiptDetailQueryEntity receiptdetailQueryEntity)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptDetailQueryInboundDetail = new WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity();
            if (receiptdetailQueryEntity != null)
            {
                receiptDetailQueryInboundDetail.IsGetAll = receiptdetailQueryEntity.IsGetAll;
                receiptDetailQueryInboundDetail.CurrentPage = receiptdetailQueryEntity.CurrentPage;
                receiptDetailQueryInboundDetail.PageSize = receiptdetailQueryEntity.PageSize;
                receiptDetailQueryInboundDetail.SortField = receiptdetailQueryEntity.SortField;
                receiptDetailQueryInboundDetail.SortDirection = receiptdetailQueryEntity.SortDirection;
                receiptDetailQueryInboundDetail.IsPalletized = receiptdetailQueryEntity.IsPalletized;
                receiptDetailQueryInboundDetail.ReceiptID = receiptdetailQueryEntity.ReceiptID;
            }
            return receiptDetailQueryInboundDetail;
        }

        private WMS6.Web.InboundServiceRef.ReceiptHistoryQueryEntity ConvertReceiptHistoryQueryEntityByInBound(WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntity)
        {
            WMS6.Web.InboundServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntityInboundDetail = null;
            if (receiptHistoryQueryEntity != null)
            {
                receiptHistoryQueryEntityInboundDetail = new WMS6.Web.InboundServiceRef.ReceiptHistoryQueryEntity {
                    IsGetAll = receiptHistoryQueryEntity.IsGetAll,
                    CurrentPage = receiptHistoryQueryEntity.CurrentPage,
                    PageSize = receiptHistoryQueryEntity.PageSize,
                    SortField = receiptHistoryQueryEntity.SortField,
                    SortDirection = receiptHistoryQueryEntity.SortDirection,
                    ReceiptID = receiptHistoryQueryEntity.ReceiptID
                };
            }
            return receiptHistoryQueryEntityInboundDetail;
        }

        private WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity ConvertReceiptHistoryQueryEntityByInBoundDetail(WMS6.Web.InboundServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntity)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntityInboundDetail = new WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity();
            if (receiptHistoryQueryEntity != null)
            {
                receiptHistoryQueryEntityInboundDetail.IsGetAll = receiptHistoryQueryEntity.IsGetAll;
                receiptHistoryQueryEntityInboundDetail.CurrentPage = receiptHistoryQueryEntity.CurrentPage;
                receiptHistoryQueryEntityInboundDetail.PageSize = receiptHistoryQueryEntity.PageSize;
                receiptHistoryQueryEntityInboundDetail.SortField = receiptHistoryQueryEntity.SortField;
                receiptHistoryQueryEntityInboundDetail.SortDirection = receiptHistoryQueryEntity.SortDirection;
                receiptHistoryQueryEntityInboundDetail.ReceiptID = receiptHistoryQueryEntity.ReceiptID;
            }
            return receiptHistoryQueryEntityInboundDetail;
        }

        protected string FormatReceiptUrl(string url, string receiptID, string receiptLineID, string ownerID)
        {
            return string.Format(url, new object[] { this.hdnFrom.Value.Trim(), receiptID, receiptLineID, ownerID, this.txtReceiptDate.Text });
        }

        private void GetDataPutawayDetail(WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            DataSet ds = InboundDetailServiceClientProxy.GetInstance().GetPutAwayDetailByPagerQueryEntity(putawayDetailQueryEntity);
            this.BindDataPutawayDetail(ds);
        }

        private void GetDataReceiptDetail(WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptDetail)
        {
            DataSet ds = InboundDetailServiceClientProxy.GetInstance().GetReceiptDetailInfoByPagerQueryEntity(receiptDetail);
            this.BindDataReceiptDetail(ds);
        }

        private void GetDataReceiptHistory(WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntity)
        {
            DataSet ds = InboundDetailServiceClientProxy.GetInstance().GetReceiptHistoryByPagerQueryEntity(receiptHistoryQueryEntity);
            this.BindDataReceiptHistory(ds);
        }

        private WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity GetPutawayDetailQueryEntity()
        {
            return (this.ViewState["PutawayDetailQueryEntity"] as WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity);
        }

        private WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity GetReceiptDetailQueryEntity()
        {
            return (this.ViewState["ReceiptDetailQueryEntity"] as WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity);
        }

        private WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity GetReceiptHistoryQueryEntity()
        {
            return (this.ViewState["ReceiptHistoryQueryEntity"] as WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity);
        }

        protected void gvPutawayDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F4021", this.gvPutawayDetail);
        }

        protected void gvPutawayDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as ReceiptInfo).PutawayDetailInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,4) </script>", false);
        }

        protected void gvPutawayDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvPutawayDetail.PageIndex * this.gvPutawayDetail.PageSize;
                e.Row.Cells[0].Text = ((e.Row.RowIndex + 1) + i).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                if (((Label) e.Row.FindControl("lblQty")) != null)
                {
                    this.PDtotalQty += decimal.Parse(((Label) e.Row.FindControl("lblQty")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblPDTotalQty.Text = base.GetPreferenceDigit(this.PDtotalQty);
            }
        }

        protected void gvPutawayDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntity = this.GetPutawayDetailQueryEntity();
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    putawayDetailQueryEntity.SortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    putawayDetailQueryEntity.SortDirection = "ASC";
                }
                putawayDetailQueryEntity.SortField = e.SortExpression;
                this.GetDataPutawayDetail(putawayDetailQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);</script>", false);
            }
        }

        protected void gvReceiptDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F4021", this.gvReceiptDetail);
        }

        protected void gvReceiptDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as ReceiptInfo).ReceiptDetailInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,4) </script>", false);
        }

        protected void gvReceiptDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                if (((Label) e.Row.FindControl("lblExpectedQty")) != null)
                {
                    this.totalExpectedQty += decimal.Parse(((Label) e.Row.FindControl("lblExpectedQty")).Text);
                }
                if (((Label) e.Row.FindControl("lblReceivedQty")) != null)
                {
                    this.totalReceivedQty += decimal.Parse(((Label) e.Row.FindControl("lblReceivedQty")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalReceivedQty.Text = base.GetPreferenceDigit(this.totalReceivedQty);
                this.lblTotalExpectedQty.Text = base.GetPreferenceDigit(this.totalExpectedQty);
            }
        }

        protected void gvReceiptDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptDetailQueryEntity = this.GetReceiptDetailQueryEntity();
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    receiptDetailQueryEntity.SortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    receiptDetailQueryEntity.SortDirection = "ASC";
                }
                receiptDetailQueryEntity.SortField = e.SortExpression;
                this.GetDataReceiptDetail(receiptDetailQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,4);</script>", false);
            }
        }

        protected void gvReceiptHistory_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F4021", this.gvReceiptHistory);
        }

        protected void gvReceiptHistory_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as ReceiptInfo).ReceiptHistoryInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,4) </script>", false);
        }

        protected void gvReceiptHistory_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvReceiptHistory.PageIndex * this.gvReceiptHistory.PageSize;
                e.Row.Cells[0].Text = ((e.Row.RowIndex + 1) + i).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                string temp = this.gvReceiptHistory.DataKeys[e.Row.RowIndex]["STATUS"].ToString();
                if (base.UserInfo.Preference.Lang.ToUpper() == "ZH-CN")
                {
                    if (temp.ToUpper() == "COMPLETED")
                    {
                        if (((Label) e.Row.FindControl("lblStatus")) != null)
                        {
                            ((Label) e.Row.FindControl("lblStatus")).Text = "完成";
                        }
                    }
                    else if ((temp.ToUpper() == "PENDING") && (((Label) e.Row.FindControl("lblStatus")) != null))
                    {
                        ((Label) e.Row.FindControl("lblStatus")).Text = "挂起";
                    }
                }
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                if (((Label) e.Row.FindControl("lblReceivedQty")) != null)
                {
                    this.RHTotalReceived += decimal.Parse(((Label) e.Row.FindControl("lblReceivedQty")).Text);
                }
                if (((Label) e.Row.FindControl("lblCompletedQty")) != null)
                {
                    this.TotalCompleted += decimal.Parse(((Label) e.Row.FindControl("lblCompletedQty")).Text);
                }
                if (((Label) e.Row.FindControl("lblAllocatedQty")) != null)
                {
                    this.TotalAllocated += decimal.Parse(((Label) e.Row.FindControl("lblAllocatedQty")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblRHTotalReceivedQty.Text = base.GetPreferenceDigit(this.RHTotalReceived);
                this.lblTotalCompletedQty.Text = base.GetPreferenceDigit(this.TotalCompleted);
                this.lblTotalAllocatedQty.Text = base.GetPreferenceDigit(this.TotalAllocated);
            }
        }

        protected void gvReceiptHistory_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            int index = e.NewSelectedIndex;
            PutawayParas putaway = new PutawayParas {
                TransID = this.gvReceiptHistory.DataKeys[index]["TRANS_ID"].ToString(),
                ReceiptID = this.gvReceiptHistory.DataKeys[index]["RECEIPT_ID"].ToString(),
                ReceiptLineID = this.gvReceiptHistory.DataKeys[index]["RECEIPT_LINE_ID"].ToString(),
                OwnerID = this.gvReceiptHistory.DataKeys[index]["OWNER_ID"].ToString(),
                SkuID = this.gvReceiptHistory.DataKeys[index]["SKU_ID"].ToString(),
                Qty = Convert.ToDecimal(this.gvReceiptHistory.DataKeys[index]["REMAIN_QTY"].ToString()),
                UomID = this.gvReceiptHistory.DataKeys[index]["UOM_ID"].ToString(),
                LotID = this.gvReceiptHistory.DataKeys[index]["LOT"].ToString(),
                FromLoc = this.gvReceiptHistory.DataKeys[index]["TO_LOC"].ToString(),
                PackID = this.gvReceiptHistory.DataKeys[index]["PACK_ID"].ToString(),
                ConditionCode = this.gvReceiptHistory.DataKeys[index]["HOLD_CODE"].ToString(),
                LpnID = this.gvReceiptHistory.DataKeys[index]["TO_LPN_ID"].ToString(),
                Status = this.ddlStatus.SelectedValue
            };
            this.Session["PutAwayParas"] = putaway;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>popManualPutAway();</script>", false);
        }

        protected void gvReceiptHistory_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntity = this.GetReceiptHistoryQueryEntity();
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    receiptHistoryQueryEntity.SortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    receiptHistoryQueryEntity.SortDirection = "ASC";
                }
                receiptHistoryQueryEntity.SortField = e.SortExpression;
                this.GetDataReceiptHistory(receiptHistoryQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,4);</script>", false);
            }
        }

        protected void lnkbtnAutoputaway_Click(object sender, EventArgs e)
        {
            this.AutoPutAway();
        }

        protected void lnkbtnClose_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> gInitLocal0 = new List<string> {
                    this.txtReceiptID.Text.Trim()
                };
                this.lblMsg.Text = InboundServiceClientProxy.GetInstance().CloseReceipt(gInitLocal0) + base.GetGlobalMsgResource("F4200_028");
                this.SetReceiptInfo2Form();
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void lnkbtnPrintPutAway_Click(object sender, EventArgs e)
        {
            this.lblMsg.Visible = false;
            try
            {
                PrintControlInfo printControlInfo;
                this.Session.Remove("PRINT_PA_TASK_DETAIL_IDS");
                List<string> taskDetailIDs = new List<string>();
                List<PrintControlInfo> printControlInfos = new List<PrintControlInfo>();
                string msg = string.Empty;
                string tempTaskDetailIDPrinted = string.Empty;
                for (int i = 0; i < this.gvPutawayDetail.Rows.Count; i++)
                {
                    if (((CheckBox) this.gvPutawayDetail.Rows[i].FindControl("chbSelect")).Checked)
                    {
                        if (this.gvPutawayDetail.DataKeys[i]["IS_PRINTED"].ToString().ToUpper() != "Y")
                        {
                            taskDetailIDs.Add(this.gvPutawayDetail.DataKeys[i]["TASK_DETAIL_ID"].ToString());
                            printControlInfo = new PrintControlInfo {
                                PrintType = "PrintPutaway",
                                DocID = this.txtReceiptID.Text.Trim(),
                                DocLineID = this.gvPutawayDetail.DataKeys[i]["TASK_DETAIL_ID"].ToString()
                            };
                            printControlInfos.Add(printControlInfo);
                        }
                        else
                        {
                            tempTaskDetailIDPrinted = tempTaskDetailIDPrinted + this.gvPutawayDetail.DataKeys[i]["TASK_DETAIL_ID"].ToString() + ",";
                        }
                    }
                }
                if (!string.IsNullOrEmpty(tempTaskDetailIDPrinted))
                {
                    msg = msg + tempTaskDetailIDPrinted.Substring(0, tempTaskDetailIDPrinted.Length - 1) + "已打印.";
                }
                if (!string.IsNullOrEmpty(msg))
                {
                    this.lblMsg.Text = msg;
                    this.lblMsg.Visible = true;
                }
                else
                {
                    if (taskDetailIDs.Count <= 0)
                    {
                        taskDetailIDs = InboundDetailServiceClientProxy.GetInstance().GetUnPrintPutawayTaskIDByReceiptID(this.txtReceiptID.Text.Trim());
                        foreach (string taskDetailID in taskDetailIDs)
                        {
                            printControlInfo = new PrintControlInfo {
                                PrintType = "PrintPutaway",
                                DocID = this.txtReceiptID.Text.Trim(),
                                DocLineID = taskDetailID
                            };
                            printControlInfos.Add(printControlInfo);
                        }
                    }
                    if (taskDetailIDs.Count <= 0)
                    {
                        this.lblMsg.Text = "没有可打印的记录.";
                        this.lblMsg.Visible = true;
                    }
                    else
                    {
                        this.Session["PRINT_PA_TASK_DETAIL_IDS"] = taskDetailIDs;
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);popPrintPutAway();</script>", false);
                        CommoneMethodService2ClientProxy.GetInstance().SavePrintControl(printControlInfos);
                        this.SetReceiptInfo2Form();
                    }
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);</script>", false);
            }
        }

        protected void lnkbtnReceiveall_Click(object sender, EventArgs e)
        {
            this.ReceivingAll();
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlReceiptType, "ReceiptType");
            base.BindData2DDLBySysCode(this.ddlStatus, "ReceiptStatus");
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnReceiptID.Value = base.Request.QueryString["ID"].ToString();
                if (base.PageQueryEntitySession != null)
                {
                    WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = base.PageQueryEntitySession as WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity;
                    if ((receiptQuery != null) && (receiptQuery.ReceiptID == this.hdnReceiptID.Value))
                    {
                        this.SetReceiptDetailQueryEntity(receiptQuery);
                    }
                    base.PageQueryEntitySession = null;
                }
                this.SetReceiptInfo2Form();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["detail"]))
            {
                if (this.ddlStatus.SelectedValue == "ReceivedComplete")
                {
                    List<string> mailList = new List<string> {
                        DateTime.Now.ToString(),
                        this.txtReceiptID.Text,
                        base.UserInfo.UserName
                    };
                    WMS6.Web.BaseInfoServiceRef.UserMstInfo user = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.hdnCreatedBy.Value, "USER_MST") as WMS6.Web.BaseInfoServiceRef.UserMstInfo;
                    if (user != null)
                    {
                        base.SandMail("Receiving", mailList, user.Email);
                    }
                }
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one'," + base.Request.QueryString["detail"].ToString() + ",4);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.lblMsg.Text = "";
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        protected void PutawayDetailbtnFirst_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity receiptQuery = this.GetPutawayDetailQueryEntity();
            receiptQuery.CurrentPage = "0";
            this.GetDataPutawayDetail(receiptQuery);
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,4); </script>", false);
        }

        protected void PutawayDetailbtnLast_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity receiptQuery = this.GetPutawayDetailQueryEntity();
            receiptQuery.CurrentPage = (this.PutawayDetailPagerFooter.TotalPages - 1).ToString();
            this.GetDataPutawayDetail(receiptQuery);
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,4); </script>", false);
        }

        protected void PutawayDetailbtnNext_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity receiptQuery = this.GetPutawayDetailQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) < (this.PutawayDetailPagerFooter.TotalPages - 1))
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) + 1).ToString();
                this.GetDataPutawayDetail(receiptQuery);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,4); </script>", false);
        }

        protected void PutawayDetailbtnPrevious_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity receiptQuery = this.GetPutawayDetailQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) > 0)
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) - 1).ToString();
                this.GetDataPutawayDetail(receiptQuery);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,4); </script>", false);
        }

        protected void PutawayDetailGoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PutawayDetailPagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity receiptQuery = this.GetPutawayDetailQueryEntity();
                receiptQuery.CurrentPage = this.PutawayDetailPagerFooter.GoToPage.ToString();
                this.GetDataPutawayDetail(receiptQuery);
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,4); </script>", false);
            }
        }

        protected void ReceiptDetailbtnFirst_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = this.GetReceiptDetailQueryEntity();
            receiptQuery.CurrentPage = "0";
            this.GetDataReceiptDetail(receiptQuery);
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,4); </script>", false);
        }

        protected void ReceiptDetailbtnLast_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = this.GetReceiptDetailQueryEntity();
            receiptQuery.CurrentPage = (this.ReceiptDetailPagerFooter.TotalPages - 1).ToString();
            this.GetDataReceiptDetail(receiptQuery);
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,4); </script>", false);
        }

        protected void ReceiptDetailbtnNext_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = this.GetReceiptDetailQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) < (this.ReceiptDetailPagerFooter.TotalPages - 1))
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) + 1).ToString();
                this.GetDataReceiptDetail(receiptQuery);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,4); </script>", false);
        }

        protected void ReceiptDetailbtnPrevious_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = this.GetReceiptDetailQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) > 0)
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) - 1).ToString();
                this.GetDataReceiptDetail(receiptQuery);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,4); </script>", false);
        }

        protected void ReceiptDetailGoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.ReceiptDetailPagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = this.GetReceiptDetailQueryEntity();
                receiptQuery.CurrentPage = this.ReceiptDetailPagerFooter.GoToPage.ToString();
                this.GetDataReceiptDetail(receiptQuery);
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,4); </script>", false);
            }
        }

        protected void ReceiptHistorybtnFirst_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptQuery = this.GetReceiptHistoryQueryEntity();
            receiptQuery.CurrentPage = "0";
            this.GetDataReceiptHistory(receiptQuery);
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,4); </script>", false);
        }

        protected void ReceiptHistorybtnLast_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptQuery = this.GetReceiptHistoryQueryEntity();
            receiptQuery.CurrentPage = (this.ReceiptHistoryPagerFooter.TotalPages - 1).ToString();
            this.GetDataReceiptHistory(receiptQuery);
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,4); </script>", false);
        }

        protected void ReceiptHistorybtnNext_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptQuery = this.GetReceiptHistoryQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) < (this.ReceiptHistoryPagerFooter.TotalPages - 1))
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) + 1).ToString();
                this.GetDataReceiptHistory(receiptQuery);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,4); </script>", false);
        }

        protected void ReceiptHistorybtnPrevious_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptQuery = this.GetReceiptHistoryQueryEntity();
            if (int.Parse(receiptQuery.CurrentPage) > 0)
            {
                receiptQuery.CurrentPage = (int.Parse(receiptQuery.CurrentPage) - 1).ToString();
                this.GetDataReceiptHistory(receiptQuery);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,4); </script>", false);
        }

        protected void ReceiptHistoryGoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.ReceiptHistoryPagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptQuery = this.GetReceiptHistoryQueryEntity();
                receiptQuery.CurrentPage = this.ReceiptHistoryPagerFooter.GoToPage.ToString();
                this.GetDataReceiptHistory(receiptQuery);
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,4); </script>", false);
            }
        }

        private void ReceivingAll()
        {
            try
            {
                string receiptID = this.txtReceiptID.Text.Trim();
                string result = InboundDetailServiceClientProxy.GetInstance().ExecuteReceivingAll(receiptID);
                if (!string.IsNullOrEmpty(result))
                {
                    this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F4200_009"), result);
                    this.lblMsg.Visible = true;
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_010");
                    this.lblMsg.Visible = true;
                }
                this.SetReceiptInfo2Form();
                if (this.ddlStatus.SelectedValue == "ReceivedComplete")
                {
                    List<string> mailList = new List<string> {
                        DateTime.Now.ToString(),
                        this.txtReceiptID.Text,
                        base.UserInfo.UserName
                    };
                    WMS6.Web.LoginServiceRef.UserMstInfo user = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.hdnCreatedBy.Value, "USER_MST") as WMS6.Web.LoginServiceRef.UserMstInfo;
                    if (user != null)
                    {
                        base.SandMail("Receiving", mailList, user.Email);
                    }
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,4);$.unblockUI();</script>", false);
            }
        }

        protected void SavePageQuery_Click(object sender, EventArgs e)
        {
            WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery = this.GetReceiptDetailQueryEntity();
            if (receiptQuery != null)
            {
                base.PageQueryEntitySession = receiptQuery;
            }
            string strUrl = this.FormatReceiptUrl("ReceivingDetail.aspx?from={0}&rid={1}&rlid={2}&owner={3}&rdate=Edit", this.txtReceiptID.Text, ((HtmlAnchor) sender).Title, this.txtOwnerID.Text);
            base.Response.Redirect(strUrl);
        }

        private void SetPutawayDetailQueryEntity(WMS6.Web.InboundDetailServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            this.ViewState["PutawayDetailQueryEntity"] = putawayDetailQueryEntity;
        }

        private void SetReceiptDetailQueryEntity(WMS6.Web.InboundDetailServiceRef.ReceiptDetailQueryEntity receiptQuery)
        {
            this.ViewState["ReceiptDetailQueryEntity"] = receiptQuery;
        }

        private void SetReceiptHistoryQueryEntity(WMS6.Web.InboundDetailServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntity)
        {
            this.ViewState["ReceiptHistoryQueryEntity"] = receiptHistoryQueryEntity;
        }

        private void SetReceiptInfo2Form()
        {
            try
            {
                string receiptID = this.hdnReceiptID.Value.ToString();
                WMS6.Web.InboundServiceRef.ReceiptDetailQueryEntity receiptdetailQueryEntity = this.ConvertReceiptDetailQueryEntityByInBound(this.GetReceiptDetailQueryEntity());
                if (receiptdetailQueryEntity == null)
                {
                    receiptdetailQueryEntity = new WMS6.Web.InboundServiceRef.ReceiptDetailQueryEntity {
                        IsGetAll = false,
                        CurrentPage = "0",
                        PageSize = this.gvReceiptDetail.PageSize.ToString(),
                        SortField = "RD.RECEIPT_ID",
                        SortDirection = "ASC",
                        ReceiptID = receiptID
                    };
                    this.ReceiptDetailPagerFooter.PageSize = this.gvReceiptDetail.PageSize;
                }
                WMS6.Web.InboundServiceRef.ReceiptHistoryQueryEntity receiptHistoryQueryEntity = this.ConvertReceiptHistoryQueryEntityByInBound(this.GetReceiptHistoryQueryEntity());
                if (receiptHistoryQueryEntity == null)
                {
                    receiptHistoryQueryEntity = new WMS6.Web.InboundServiceRef.ReceiptHistoryQueryEntity {
                        IsGetAll = false,
                        CurrentPage = "0",
                        PageSize = this.gvReceiptHistory.PageSize.ToString(),
                        SortField = "IT.RECEIPT_LINE_ID",
                        SortDirection = "ASC",
                        ReceiptID = receiptID
                    };
                    this.ReceiptHistoryPagerFooter.PageSize = this.gvReceiptHistory.PageSize;
                }
                WMS6.Web.InboundServiceRef.PutawayDetailQueryEntity putawayDetailQueryEntity = this.ConvertPutawayDetailQueryEntityByInBound(this.GetPutawayDetailQueryEntity());
                if (putawayDetailQueryEntity == null)
                {
                    putawayDetailQueryEntity = new WMS6.Web.InboundServiceRef.PutawayDetailQueryEntity {
                        IsGetAll = false,
                        CurrentPage = "0",
                        PageSize = this.gvPutawayDetail.PageSize.ToString(),
                        SortField = "TD.DOC_LINE_ID",
                        SortDirection = "ASC",
                        ReceiptID = receiptID
                    };
                    this.PutawayDetailPagerFooter.PageSize = this.gvPutawayDetail.PageSize;
                }
                ReceiptInfo receiptInfo = InboundServiceClientProxy.GetInstance().GetReceiptInfoByID4ExecByPagerQuery(receiptID, receiptdetailQueryEntity, receiptHistoryQueryEntity, putawayDetailQueryEntity);
                base.DataEntityViewState = receiptInfo;
                if (receiptInfo != null)
                {
                    receiptdetailQueryEntity.IsPalletized = receiptInfo.IsPalletized;
                    this.SetReceiptDetailQueryEntity(this.ConvertReceiptDetailQueryEntityByInBoundDetail(receiptdetailQueryEntity));
                    this.SetReceiptHistoryQueryEntity(this.ConvertReceiptHistoryQueryEntityByInBoundDetail(receiptHistoryQueryEntity));
                    this.SetPutawayDetailQueryEntity(this.ConvertPutawayDetailQueryEntityByInBoundDetail(putawayDetailQueryEntity));
                    this.txtReceiptID.Text = receiptInfo.ReceiptID;
                    this.ddlStatus.SelectedValue = receiptInfo.Status;
                    this.txtReceiptDate.Text = base.GetPreferenceShortDate(receiptInfo.ReceiptDate);
                    this.txtOwnerID.Text = receiptInfo.OwnerID;
                    this.txtVendorID.Text = receiptInfo.VendorID;
                    this.txtVendorRef.Text = receiptInfo.VendorRef;
                    this.ddlReceiptType.SelectedValue = receiptInfo.ReceiptType;
                    this.txtPoID.Text = receiptInfo.PoID;
                    this.txtExceptReceiptDate.Text = base.GetPreferenceShortDate(receiptInfo.ExpectedReceiptDate);
                    this.txtExternalReceiptID.Text = receiptInfo.ExternalReceiptID;
                    this.txtRMA.Text = receiptInfo.Rma;
                    this.txtPackingSlipNum.Text = receiptInfo.PackingSlipNumber;
                    this.txtWaraHouseRef.Text = receiptInfo.WarehouseRef;
                    this.chbSAPAuthentication.Checked = receiptInfo.SAPAuthentication == "Y";
                    this.chkboxPalletAudit.Checked = receiptInfo.IsPalletAudit == "Y";
                    this.txtTotalExceptQty.Text = base.GetPreferenceDigit(receiptInfo.TotalExpectedQty);
                    this.txtTotalReceiptQty.Text = base.GetPreferenceDigit(receiptInfo.TotalReceivedQty);
                    this.txtTotalCube.Text = base.GetPreferenceDigit(receiptInfo.TotalCube);
                    this.txtTotalGrossWeight.Text = base.GetPreferenceDigit(receiptInfo.TotalGrossWgt);
                    this.hdnCreatedBy.Value = receiptInfo.CreatedBy;
                    this.BindDataReceiptDetail(receiptInfo.DataSetReceiptDetails);
                    this.BindDataReceiptHistory(receiptInfo.DataSetReceiptHistorys);
                    this.BindDataPutawayDetail(receiptInfo.DataSetPutawayDetails);
                    this.txtReceiptID.Enabled = false;
                    this.btnSave.Enabled = false;
                    if (string.Compare(receiptInfo.Status, "closed", true) == 0)
                    {
                        this.btnBatchReceive.Enabled = false;
                        this.btnConfirmPA.Enabled = false;
                        this.htmlbtnAction.Disabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        public class PutawayParas
        {
            public string ConditionCode { get; set; }

            public string FromLoc { get; set; }

            public string LotID { get; set; }

            public string LpnID { get; set; }

            public string OwnerID { get; set; }

            public string PackID { get; set; }

            public decimal Qty { get; set; }

            public string ReceiptID { get; set; }

            public string ReceiptLineID { get; set; }

            public string SkuID { get; set; }

            public string Status { get; set; }

            public string TransID { get; set; }

            public string UomID { get; set; }
        }
    }
}

